home *** CD-ROM | disk | FTP | other *** search
- // RTLI for VCL. Implements the exception message box that
- // gives detailed exception location information
-
- unit LIVCLInt;
-
- interface
-
- procedure RTLIShowException(ExceptObject: TObject; ExceptAddr: Pointer);
-
- implementation
-
- uses LIPrgInt, SysUtils, Forms, Windows;
-
- type
- TExceptionHandlerObject = class
- constructor Create;
- procedure HandleExceptions(Sender: TObject; E: Exception);
- end;
-
- var
- PrevInitProc: Pointer;
- ExceptionHandlerObject: TExceptionHandlerObject = nil;
-
- procedure RTLIShowException(ExceptObject: TObject; ExceptAddr: Pointer);
- var
- LocInfo: TLocInfo;
- Msg,ModuleName: String;
- Buffer: array[0..259] of Char;
- begin
- GetLocationInfo(ExceptAddr, LocInfo);
- if ExceptObject is Exception then
- Msg := Exception(ExceptObject).Message
- else
- Msg := '**Unknown**';
- GetModuleFileName(HInstance, Buffer, SizeOf(Buffer));
- ModuleName := ExtractFileName(Buffer);
- with LocInfo do
- begin
- if liFileName = '' then
- liFileName := '**Unknown**';
- if liUnitName = '' then
- liUnitName := '**Unknown**';
- Msg := Format('%s' + ^J +
- 'Exception address %8.8x' + ^J +
- 'Module %s, Unit %s, %8.8x - %8.8x' + ^J +
- 'File %s line %d offset %8.8x' + ^J +
- 'Between %s(%8.8x) and %s(%8.8x)',
- [Msg,
- Integer(ExceptAddr),
- ModuleName, liUnitName, liUnitBegOfs, liUnitEndOfs,
- liFileName, liLineNo, liLineOfs,
- liPubSym1Name, liPubSym1Ofs, liPubSym2Name, liPubSym2Ofs]);
- end;
- MessageBox(0, PChar(Msg), 'Application Error', mb_Ok or mb_IconStop or mb_TaskModal);
- end;
-
- constructor TExceptionHandlerObject.Create;
- begin
- Application.OnException := HandleExceptions;
- end;
-
- procedure TExceptionHandlerObject.HandleExceptions(Sender: TObject; E: Exception);
- begin
- RTLIShowException(E, ExceptAddr);
- end;
-
- procedure RTLIInitProc;
- begin
- ExceptionHandlerObject := TExceptionHandlerObject.Create;
- if Assigned(PrevInitProc) then
- TProcedure(PrevInitProc);
- end;
-
- procedure RTLIExceptHandler(ExceptObject: TObject; ExceptAddr: Pointer);
- begin
- RTLIShowException(ExceptObject, ExceptAddr);
- Halt(1);
- end;
-
- initialization
- PrevInitProc := InitProc;
- InitProc := @RTLIInitProc;
- ExceptProc := @RTLIExceptHandler;
- finalization
- ExceptionHandlerObject.Free;
- end.
-